home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 109_01.zip / LPR.C < prev    next >
Text File  |  1993-06-26  |  2KB  |  111 lines

  1. /*
  2.     Line printer formatter 
  3.  
  4.     Written by Leor Zolman
  5.            May 28, 1980
  6.  
  7.     First prints all files named on the command line, and then
  8.     asks for names of more files to print until a null line is typed.
  9.     Control-Q aborts current printing and goes to next file.
  10.  
  11.     Paper should be positioned ready to print on the first page; each
  12.     file is always printed in an even number of pages so that new files
  13.     always start on the same phase of fan-fold paper.
  14.  
  15.     Tabs are expanded into spaces.
  16. */
  17.  
  18. #define FF 0x00        /* formfeed character, or zero if not supported */
  19. #define PGLEN 66    /* lines per lineprinter page */
  20.  
  21. int colno, linesleft;
  22.  
  23. main(argc,argv)
  24. char **argv;
  25. {
  26.     int i;
  27.     int pgno, date[20], linebuf[135];
  28.     char fnbuf[30], *fname;
  29.     int fd, ibuf[134];
  30.     char *gets();
  31.     pgno = colno = 0;
  32.     linesleft = PGLEN; 
  33.     printf("What is today's date? ");
  34.     gets(date);
  35.     while (1)
  36.     {
  37.         if (argc-1)
  38.          {
  39.             fname = *++argv;
  40.             argc--;
  41.          }
  42.         else
  43.          {
  44.             printf("\nEnter file to print, or CR if done: ");
  45.             if (!*(fname = gets(fnbuf))) break;
  46.          }
  47.  
  48.         if ((fd = fopen(fname,ibuf)) == -1)
  49.          {
  50.             printf("Can't open %s\n",fname);
  51.             continue;
  52.          }
  53.         else printf("\nPrinting %-13s",fname);
  54.  
  55.         for (pgno = 1; ; pgno++)
  56.          {
  57.             putchar('*');
  58.             sprintf(linebuf,"\n%28s%-13s%5s%-3d%20s\n\n",
  59.                 "file: ",fname,"page ",pgno,date);
  60.             linepr(linebuf);
  61.         loop:    if (!fgets(linebuf,ibuf)) break;
  62.             if (kbhit() && getchar() == 0x11) break;
  63.             linepr(linebuf);
  64.             if (linesleft > 2) goto loop;
  65.             formfeed();
  66.          }
  67.         formfeed();
  68.         if (pgno % 2) formfeed();
  69.         fabort(fd);
  70.     }
  71. }
  72.  
  73. linepr(string)
  74. char *string;
  75. {
  76.     char c;
  77.     while (c = *string++)
  78.       switch (c) {
  79.         case '\n':    
  80.         putlpr('\r');
  81.         putlpr('\n');
  82.         colno = 0;
  83.         linesleft--;
  84.         break;
  85.  
  86.         case '\t':
  87.         do {
  88.           putlpr(' ');
  89.           colno++;
  90.         } while (colno % 8);
  91.         break;
  92.  
  93.         default:                    
  94.         putlpr(c);
  95.         colno++;
  96.     }
  97. }
  98.  
  99. putlpr(c)
  100. char c;
  101. {
  102.     bios(5,c);
  103. }
  104.  
  105. formfeed()
  106. {
  107.     if (FF) putlpr(FF);
  108.     else while (linesleft--) putlpr('\n');
  109.     linesleft = PGLEN;
  110. }
  111.